// TabCtrlEx.cpp : implementation file
//

#include "stdafx.h"
#include "ctptt.h"
#include "TabCtrlEx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTabCtrlEx

CTabCtrlEx::CTabCtrlEx()
{
	m_colorBK=DLG_BK1; 
}

CTabCtrlEx::~CTabCtrlEx()
{
}


BEGIN_MESSAGE_MAP(CTabCtrlEx, CTabCtrl)
	//{{AFX_MSG_MAP(CTabCtrlEx)
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTabCtrlEx message handlers

//DEL void CTabCtrlEx::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
//DEL {
//DEL 	// TODO: Add your message handler code here and/or call default
//DEL 	//CBrush brushBK(m_colorBK); 
//DEL          
//DEL     //::SetBkColor(lpDrawItemStruct->hDC,bkColor); 
//DEL /*	char     szTabText[100];      
//DEL     TC_ITEM  tci;   
//DEL 	memset(szTabText,   '/0',   sizeof(szTabText));      
//DEL     tci.mask                 =   TCIF_TEXT;      
//DEL     tci.pszText         =   szTabText;      
//DEL     tci.cchTextMax     =   sizeof(szTabText)-1;      
//DEL      
//DEL     GetItem(lpDrawItemStruct->itemID,   &tci);    
//DEL     TextOut(lpDrawItemStruct->hDC,      
//DEL         lpDrawItemStruct->rcItem.left+5,      
//DEL         lpDrawItemStruct->rcItem.top+5,      
//DEL         tci.pszText,      
//DEL         lstrlen(tci.pszText));    */  
//DEL 
//DEL 	//CTabCtrl::OnDrawItem(nIDCtl, lpDrawItemStruct);
//DEL }

void CTabCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{  
    CBrush brushBK(m_colorBK); 
     
    char     szTabText[100];      
    UINT     bkColor;      
    CBrush   *cbr;      
    TC_ITEM  tci;      
    LOGBRUSH m_LogBrush;      


   
    cbr   =   &brushBK;      
    cbr->GetLogBrush(&m_LogBrush);      
    bkColor   =   m_LogBrush.lbColor;   
//  TRACE("item:%d/n",lpDrawItemStruct->itemID);       

    memset(szTabText,   '/0',   sizeof(szTabText));      
    tci.mask                 =   TCIF_TEXT|TCIF_IMAGE;      
    tci.pszText         =   szTabText;      
    tci.cchTextMax     =   sizeof(szTabText)-1;      
    FillRect(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,*cbr);    
     
    GetItem(lpDrawItemStruct->itemID,&tci);  


	::SetBkColor(lpDrawItemStruct->hDC,bkColor);  
	if(tci.iImage>=0)
	{
		CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);   
		if (!pDC) return;   
		int nSavedDC = pDC->SaveDC();   

		POINT pt;pt.x=lpDrawItemStruct->rcItem.left+2;pt.y=lpDrawItemStruct->rcItem.top+2;
		GetImageList()->Draw(pDC,tci.iImage,pt,0);
		pDC->RestoreDC(nSavedDC);   

		//::DrawIcon(lpDrawItemStruct->hDC,
		//	lpDrawItemStruct->rcItem.left-2,
		//	lpDrawItemStruct->rcItem.top-2,
		//	GetImageList()->ExtractIcon(tci.iImage));

		TextOut(lpDrawItemStruct->hDC,      
			lpDrawItemStruct->rcItem.left+5+16,      
			lpDrawItemStruct->rcItem.top+5,      
			tci.pszText,      
			lstrlen(tci.pszText)); 
	}
	else
	{
		TextOut(lpDrawItemStruct->hDC,      
			lpDrawItemStruct->rcItem.left+5,      
			lpDrawItemStruct->rcItem.top+5,      
			tci.pszText,      
			lstrlen(tci.pszText)); 
	}
     
} 

BOOL CTabCtrlEx::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	
	CBrush brushBK(m_colorBK); 
    CRect rect; 
    this->GetClientRect(rect); 
    pDC->FillRect(rect,&brushBK); 
    TRACE("%d,%d,%d,%d/n",rect.left,rect.top,rect.right,rect.bottom); 
    return TRUE; 
	//return CTabCtrl::OnEraseBkgnd(pDC);
}
